<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>手写call以及apply函数</title>
</head>

<body>
  <script>
    const obj = {
      a: 1
    }
    function myFn(a, b, c) {
      console.log(this)
      console.log(a, b, c)
    }
    Function.prototype.myCall = function (_this, ...ags) {
      const key = Symbol()
      _this[key] = this
      _this[key](...ags)
      Reflect.deleteProperty(_this, key)
    }
    Function.prototype.myApply = function (_this, ags) {
      ags = ags ? ags : []
      const key = Symbol()
      _this[key] = this
      _this[key](...ags)
      Reflect.deleteProperty(_this, key)
    }
    myFn.myCall(obj, 1, 2, 3)
    myFn.myApply(obj, [1, 2, 3])
  </script>
</body>

</html>